// request.ts
import axios from "./httpIntercept";
import {Notify} from "quasar";
// import qs from "qs";

export class http {
    /**
     * get方法
     * @param {string} url 路径
     * @param {object} params 参数
     */
    static get = (url: string, params?: any) => {
        return new Promise((resolve, reject) => {
            axios.get(url, { params: params }).then((res:any) => {
                if (res.code !== 0) {
                    return reject();
                };
                resolve(res?.data);
            }).catch(err => {
                reject(err);
            })
        })
    }

    static delete = (url: string, params?: any) => {
        return new Promise((resolve, reject) => {
            axios.delete(url, {params}).then((res:any) => {
                if (res.code !== 0) return reject();
                resolve(res?.data);
            }).catch(err => {
                reject(err);
            })
        })
    }

    static post = (url: string, params?: any) => {
        return new Promise((resolve, reject) => {
            axios.post(url, params).then((res:any) => {
                if (res.user_info) return resolve(res); //处理换取token接口特别处理
                if (res.code !== 0) return reject();
                resolve(res?.data);
            }).catch(err => {
                reject(err);
            })
        })
    }

    static uploadFile = (params?: any) => {
        const url:string = `/common/uploadFileToFtp?conversionImage=Y`;
        return new Promise((resolve, reject) => {
            axios.post(url, params,{headers: {'Content-Type': 'multipart/form-data'}}).then((res:any) => {
                resolve(res?.data);
            }).catch(err => {
                reject(err);
            })
        })
    }
}

